<template>
  <div class="advert-space">
    <el-form>
      <el-form-item>
        <el-button @click="$router.push({
          name: 'create-or-update-space'
        })">添加广告位</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="spaceInfo"
      style="width: 100%">
      <el-table-column
        prop="date"
        label="spaceKey"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="广告位名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="updateTime"
        label="更新时间">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button @click="handleEdit(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
import { getAllSpaces } from '@/services/advertise'

export default Vue.extend({
  name: 'AdvertSpaceIndex',
  data () {
    return {
      spaceInfo: []
    }
  },
  created () {
    this.loadSpace()
  },
  methods: {
    async loadSpace () {
      const { data } = await getAllSpaces()
      this.spaceInfo = data.content
    },
    handleEdit (ad: any) {
      this.$router.push({
        name: 'create-or-update-space',
        query: {
          id: ad.id
        }
      })
    }
  }
})
</script>

<style lang="scss" scoped></style>
